package com.shop.model;

import org.json.JSONException;
import org.json.JSONObject;

import java.sql.Timestamp;

/**
 * Created by Acer on 2016/7/25.
 */
public class Product {
    private int pid;
    private String pname;
    private double market_price;
    private double shop_price;
    private String image;
    private String pdesc;
    private int is_hot;
    private Timestamp pdate;
    private int csid;
    private String csname;

    public Product() {
    }
    public Product(Integer pid, String pname,
                   double market_price, double shop_price,
                   String image, String pdesc, Integer is_hot,
                    Integer csid) {
        this.pid = pid;
        this.pname = pname;
        this.market_price = market_price;
        this.shop_price = shop_price;
        this.image = image;
        this.pdesc = pdesc;
        this.is_hot = is_hot;

        this.csid = csid;
    }

    public Product(Integer pid, String pname,
                   double market_price, double shop_price,
                   String image, String pdesc, Integer is_hot,
                   Timestamp pdate, Integer csid) {
        this.pid = pid;
        this.pname = pname;
        this.market_price = market_price;
        this.shop_price = shop_price;
        this.image = image;
        this.pdesc = pdesc;
        this.is_hot = is_hot;
        this.pdate = pdate;
        this.csid = csid;
    }
    public Product(Integer pid, String pname,
                   double market_price, double shop_price,
                   String image, String pdesc, Integer is_hot,
                   Timestamp pdate,Integer csid, String csname) {
        this.pid = pid;
        this.pname = pname;
        this.market_price = market_price;
        this.shop_price = shop_price;
        this.image = image;
        this.pdesc = pdesc;
        this.is_hot = is_hot;
        this.pdate = pdate;
        this.csid = csid;
        this.csname= csname;
    }

    public Product(Integer pid,
                   String pname,
                   double market_price,
                   double shop_price,
                   String pdesc,
                   int csid) {
        this.pid=pid;
        this.pname=pname;
        this.market_price=market_price;
        this.shop_price=shop_price;
        this.pdesc=pdesc;
        this.csid=csid;
    }

    public int getPid() {
        return pid;
    }

    public void setPid(int pid) {
        this.pid = pid;
    }

    public int getCsid() {
        return csid;
    }

    public void setCsid(int csid) {
        this.csid = csid;
    }

    public String getPname() {
        return pname;
    }

    public void setPname(String pname) {
        this.pname = pname;
    }

    public double getMarket_price() {
        return market_price;
    }

    public void setMarket_price(double market_price) {
        this.market_price = market_price;
    }

    public double getShop_price() {
        return shop_price;
    }

    public void setShop_price(double shop_price) {
        this.shop_price = shop_price;
    }

    public String getImage() {
        return "/img/products/"+pid+".png";
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getPdesc() {
        return pdesc;
    }

    public void setPdesc(String pdesc) {
        this.pdesc = pdesc;
    }

    public int getIs_hot() {
        return is_hot;
    }

    public void setIs_hot(int is_hot) {
        this.is_hot = is_hot;
    }

    public Timestamp getPdate() {
        return pdate;
    }

    public void setPdate(Timestamp pdate) {
        this.pdate = pdate;
    }

    public String getCsname() {
        return csname;
    }

    public void setCsname(String csname) {
        this.csname = csname;
    }

    public Product(JSONObject json) throws JSONException {
        this.pid=json.getInt("pid");
        this.pname=json.getString("pname");
        this.market_price=json.getDouble("market_price");
        this.shop_price=json.getDouble("shop_price");
        this.pdesc=json.getString("pdesc");


    }
}
